import { ColumnGroupType, ColumnType } from "antd/es/table"
import { Link } from "react-router-dom"

import { constant, insuranceModeList } from "@/utils/const"
import {
	formatTime,
	getCardsName,
	getLabelByValue,
	getOutsTypeName,
	getTypeName,
	handleNumber,
	handleNumberColor
} from "@/utils/util"

import TableContentLink from "../formItems/gameList/tableContentLink"

const insure = (
	newFormat: (arg: string) => string,
	_getFromDic: (arg: string, strictlyLabel?: boolean) => any
): Record<string, ColumnGroupType<any> | ColumnType<any>> => ({
	insure_handCode: {
		key: "insure_handCode",
		align: "center",
		dataIndex: "handCode",
		width: 190,
		title: newFormat("dxn.game_list.hand_id"),
		render: (handCode: string) => <Link to={`/dxn/gameManager/gameList/gameBase?handId=${handCode}`}>{handCode}</Link>
	},
	insure_tableCode: {
		key: "insure_tableCode",
		align: "center",
		dataIndex: "tableCode",
		width: 190,
		title: newFormat("dxn.card_ables_list.table_id"),
		render: (tableCode: string) => (
			<TableContentLink
				name={tableCode}
				to="/dxn/gameManager/cardTablesList/cardTablesBase"
				queryParams={{ tableId: tableCode }}
			/>
		)
	},
	insure_tableType: {
		key: "insure_tableType",
		align: "center",
		dataIndex: "tableType",
		width: 100,
		title: newFormat("dxn.card_ables_list.game_name"),
		render: _getFromDic("gameType", false)
	},
	insure_clubId: {
		key: "insure_clubId",
		align: "center",
		dataIndex: "clubId",
		width: 100,
		title: newFormat("dxn.card_ables_list.club_id"),
		render: (clubId: string) => <Link to={`/dxn/clubManager/clubList?clubId=${clubId}`}>{clubId}</Link>
	},
	insure_roundNo: {
		key: "insure_roundNo",
		align: "center",
		dataIndex: "roundNo",
		width: 70,
		title: newFormat("dxn.card_ables_list.hand_brand")
	},
	insure_roundCode: {
		key: "insure_roundCode",
		align: "center",
		dataIndex: "roundCode",
		width: 70,
		title: newFormat("dxn.game_list.rounds"),
		render: (roundCode: number) => getTypeName(roundCode, constant.roundCode)
	},
	insure_userName: {
		key: "insure_userName",
		align: "center",
		dataIndex: "userName",
		width: 120,
		title: newFormat("dxn.card_ables_list.member_account")
	},
	insure_parentProxyName: {
		key: "insure_parentProxyName",
		align: "center",
		dataIndex: "parentProxyName",
		width: 150,
		title: newFormat("funds.proxy_member_funds_record.parent_proxy_name")
	},
	insure_topProxyName: {
		key: "insure_topProxyName",
		align: "center",
		dataIndex: "topProxyName",
		width: 150,
		title: newFormat("funds.proxy_member_funds_record.top_proxy_name")
	},
	insure_insuredOrderId: {
		key: "insure_insuredOrderId",
		align: "center",
		dataIndex: "insuredOrderId",
		width: 180,
		title: newFormat("dxn.game_list.insurance_bill_number"),
		render: (insuredOrderId: string, record: any) => (record.buyType === 0 ? "-" : insuredOrderId)
	},
	insure_insuranceMode: {
		key: "insure_insuranceMode",
		align: "center",
		dataIndex: "insuranceMode",
		width: 180,
		title: newFormat("dxn.card_ables_list.insurance_type"),
		render: (insuranceMode: number) => getLabelByValue(insuranceMode, insuranceModeList)
	},
	insure_buyType: {
		key: "insure_buyType",
		align: "center",
		dataIndex: "buyType",
		width: 120,
		title: newFormat("dxn.game_list.purchase_type"),
		render: (buyType: number) => getTypeName(buyType, constant.buyType)
	},
	insure_createTime: {
		key: "insure_createTime",
		align: "center",
		dataIndex: "createTime",
		width: 160,
		title: newFormat("dxn.game_list.insurance_purchase_time"),
		render: (createTime: string) => formatTime(createTime)
	},
	insure_orderId: {
		key: "insure_orderId",
		align: "center",
		dataIndex: "orderId",
		width: 180,
		title: newFormat("dxn.game_list.club_game_betting_number"),
		render: (orderId: string) => orderId || "-"
	},
	insure_insuranceModeOuts: {
		key: "insure_insuranceModeOuts",
		align: "center",
		dataIndex: "insuranceMode",
		width: 180,
		title: newFormat("dxn.card_ables_list.outs_type"),
		render: (insuranceMode: number, record: any) => (insuranceMode === 2 ? "-" : getOutsTypeName(record.outsType))
	},
	insure_potNo: {
		key: "insure_potNo",
		align: "center",
		dataIndex: "potNo",
		width: 100,
		title: newFormat("dxn.game_list.pot_no"),
		render: (potNo: string) => (potNo !== undefined ? (potNo === "0" ? "主池" : "边池" + potNo) : "-")
	},
	insure_potAmount: {
		key: "insure_potAmount",
		align: "center",
		dataIndex: "potAmount",
		width: 120,
		title: newFormat("dxn.game_list.pot"),
		render: (potAmount: string, record: any) => handleNumber(record.currency, potAmount)
	},
	insure_betAmount: {
		key: "insure_betAmount",
		align: "center",
		dataIndex: "betAmount",
		width: 120,
		title: newFormat("dxn.game_list.betting_amount"),
		render: (betAmount: string, record: any) => handleNumber(record.currency, betAmount)
	},
	insure_insuredAmount: {
		key: "insure_insuredAmount",
		align: "center",
		dataIndex: "insuredAmount",
		width: 120,
		title: newFormat("dxn.game_list.insured_amount"),
		render: (insuranceAmount: string, record: any) =>
			record.buyType === 0 ? "-" : handleNumber(record.currency, insuranceAmount)
	},
	insure_insuredNetAmount: {
		key: "insure_insuredNetAmount",
		align: "center",
		dataIndex: "insuredNetAmount",
		width: 120,
		title: newFormat("dxn.card_ables_list.insurance_win_or_loss"),
		render: (insuredNetAmount: number, record: any) =>
			insuredNetAmount === 2 ? (
				"-"
			) : (
				<div style={{ color: handleNumberColor(record.insuredNetAmount) }}>
					{record.buyType === 0 ? "-" : handleNumber(record.currency, `${insuredNetAmount}`)}
				</div>
			)
	},
	insure_insuredRewards: {
		key: "insure_insuredRewards",
		align: "center",
		dataIndex: "insuredRewards",
		width: 120,
		title: (
			<>
				<span>{newFormat("dxn.card_ables_list.insurance_payout")}</span>
				<br />
				<span>{newFormat("dxn.card_ables_list.extract_ev_value")}</span>
			</>
		),
		render: (insuredRewards: string, record: any) =>
			record.buyType === 0 || Number(insuredRewards) === 0 ? "-" : handleNumber(record.currency, insuredRewards)
	},
	insure_handCards: {
		key: "insure_handCards",
		align: "center",
		dataIndex: "handCards",
		width: 120,
		title: newFormat("dxn.game_list.player_hand"),
		render: (handCards: string) => getCardsName(handCards)
	},
	insure_publicCards: {
		key: "insure_publicCards",
		align: "center",
		dataIndex: "publicCards",
		width: 150,
		title: newFormat("dxn.game_list.public_brand_information"),
		render: (publicCards: string) => getCardsName(publicCards)
	}
})
export default insure
